﻿
/*
Select File > New and then select ActionScript File. Save the document as Singleton.as. 
Type the following ActionScript code into the Script window: /**
    Singleton class
    author: John Doe
    version: 0.53
    modified: 6/24/2008
    copyright: Adobe Systems Incorporated
*/

class Singleton {
    private static var instance:Singleton = null;
    public // code on a keyframe on the main timeline
// firefox-friendly getURL from projector
// works if IE is default browser too

var swfUrl:String = _root._url;
var lastSlashIndex:Number = swfUrl.lastIndexOf("/");
var pipeIndex:Number = swfUrl.indexOf("|");
var baseUrl:String;
if (pipeIndex >= 0)
{
    baseUrl = swfUrl.substring(0, pipeIndex);
    baseUrl += ":";
}
else
{
    baseUrl = "";
}
baseUrl += swfUrl.substring(pipeIndex + 1, lastSlashIndex + 1);

myButton.onRelease = function()
{
    var targetUrl:String = baseUrl + "test.html";
    getURL(targetUrl, "_blank");
};function trackChanges():Void {
        trace("tracking changes.");
    }
    public static function getInstance():Singleton {
        if (Singleton.instance == null) {
            trace("creating new Singleton.");
            Singleton.instance = new Singleton();
        }
        return Singleton.instance;
    }
}

/*
Save the Singleton.as document. 
Select File > New and then select Flash Document to create a new FLA file, and save it as singleton_test.fla in the same directory as you saved the Singleton class file. 
Type the following ActionScript code into Frame 1 of the Timeline:
*/
Singleton.getInstance().trackChanges(); // tracking changes.

var s:Singleton = Singleton.getInstance(); // tracking changes.
s.trackChanges();

/*
Save the Flash document. 
Select Control > Test Movie to test the document. 
*/